<template>
  <div>
    <common-head title="修改联系人"/>
    <div class="wrap">
      <van-address-edit
        :area-list="areaJson"
        show-postal
        show-set-default
        show-delete
        :address-info="addressInfo"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        @delete="deleteContact"
      />
    </div>
  </div>
</template>

<script>
import CommonHead from '../../components/CommonHead.vue'
import areaJson from 'utils/area'
import { mapMutations, mapState } from 'vuex'
import { Toast } from 'vant'
export default {
  data () {
    return {
      areaJson,
      addressInfo: {}
    }
  },
  created () {
    this.initAddressInfo()
  },
  methods: {
    deleteContact (params) {
     
    },
    // 点击新增地址
    onSave (contact) {
      this.set_contact({
        contact,
        index: parseInt(this.$route.query.index)
      })
      Toast('修改成功')
      this.$router.go(-1)
    },
    initAddressInfo () {
      this.addressInfo = this.contacts[parseInt(this.$route.query.index)]
    },
    ...mapMutations('contact', ['set_contact'])
  },
  components: { CommonHead },
  computed: {
    ...mapState({
      contacts: state => state.contact.contacts
    })
  }
}
</script>

<style lang="scss" scoped>
.wrap{
  margin-top: 46px;
}
</style>
